<style>
table{
	width: 100%;
}
#delivery-order-ticket-model-form textarea{
	width: 300px;
	height: 55px;
}
#delivery-order-ticket-model-form input[type="text"]{
	width: 300px;
}
.lradio span input,.lradio span label{
	float: left;
	margin-right: 5px; 
}
span label,span input, span span{
	float: left
}
</style>
<div class="form">


<?php $form = $this->beginWidget('GxActiveForm', array(
	'id' => 'delivery-order-ticket-model-form',
	'enableAjaxValidation' => false,
));
?>

	<p class="note">
		<?php echo Yii::t('DeliveryModule.main', 'Fields with'); ?> <span class="required">*</span> <?php echo Yii::t('DeliveryModule.main', 'are required'); ?>.
	</p>

	<?php echo $form->errorSummary($model); ?>
	<table>
		<tr>
			<td valign="top">
				<fieldset><legend><?php echo Yii::t('DeliveryModule.main', 'Ticket');?></legend>
				<table>
					<tr>
						<td colspan="2">
							<?php echo $form->radioButtonList($model, 'ticket_type', array(0=>'Trong nước', 1=>'Quốc tế'), array('separator'=>'<span>&nbsp;&nbsp;</span>'));?>
						</td>
						<td colspan="2"></td>
					</tr>
					<tr>
						<td>
							<?php echo $form->labelEx($model,'code'); ?></td>
						<td>
					<?php echo $form->textField($model, 'code', array('maxlength' => 255, 'style'=>'width: 100px')); ?></td>
					<td><?php echo $form->labelEx($model,'start_datetime'); ?></td>
					<td><?php echo $form->textField($model, 'start_datetime', array('maxlength' => 255, 'style'=>'width: 100px')); ?></td>
					</tr>
				</table>
				</div><!-- row -->
				</fieldset>
				
				<!--  Thông tin người gửi -->
				<fieldset><legend>Thông tin người gửi</legend>
				<table>
					<tr>
					<td><?php echo $form->labelEx($model,'customer_id'); ?></td>
					<td><?php 
					if(isset($model->customer_id) && $model->customer_id>0){
						$cusName = DeliveryCustomerModel::model()->findByPk($model->customer_id)->name;
					}else{
						$cusName='';
					}
					echo CHtml::textField('cus_name',$cusName,array('id'=>'cus_name', 'style'=>'width: 250px;', 'readonly'=>'readonly'));?>
					<?php echo $form->hiddenField($model, 'customer_id'); ?>
					
						<a style="float: right;margin: 5px 10px;" id="cus-dialog" rel="tooltip" class="btn" href="#"><i class="icon-plus-sign"></i></a>
						<div id="dialog-cus"></div>
						<script type="text/javascript">
						    $("#cus-dialog").click(function ()    {
						        $('#dialog-cus').html('<iframe frameborder="0" width="800" height="450" src="<?php echo Yii::app()->createUrl('/delivery/customer/listChoice')?>"></iframe>')
						        .dialog({
						            modal: true,
						            dialogClass: 'dialog-chose',
						            //buttons: {"Chose":function(){alert('chosed')}},
						            height: 550,
						            width: 830,
						            title: 'Danh sách khách hàng'
						        });
						    });
						    function selectCus(id) {
						    	$.ajax({
						    	  url: "<?php echo Yii::app()->createUrl('/delivery/customer/getCus')?>",
						    	  data: "id="+id,
						    	  dataType: 'JSON',
						    	  success: function(data){
						    		  $("#DeliveryOrderTicketModel_customer_id").attr("value",id);
						    		  $("#cus_name").attr("value",data.name);
						    		  $("#DeliveryOrderTicketModel_sender_company").attr("value",data.company);
						    		  $("#DeliveryOrderTicketModel_sender_address").attr("value",data.address);
						    		  $("#DeliveryOrderTicketModel_sender_phone").attr("value",data.phone);
						    	  }
						    	});
						    	$("#dialog-cus").dialog("close");
						    }
						</script>
					</td>
					</tr>
					<tr>
					<td><?php echo $form->labelEx($model,'sender_company'); ?></td>
					<td><?php echo $form->textArea($model, 'sender_company', array('maxlength' => 255,)); ?></td>
					</tr>
					<tr>
					<td><?php echo $form->labelEx($model,'sender_address'); ?></td>
					<td><?php echo $form->textArea($model, 'sender_address', array('maxlength' => 255,)); ?></td>
					</tr>
					<tr>
					<td><?php echo $form->labelEx($model,'sender_phone'); ?></td>
					<td><?php echo $form->textField($model, 'sender_phone', array('maxlength' => 100,)); ?></td>
					</tr>
				</table>
				</div><!-- row -->
				</fieldset>
				
				<!--  Dịch vụ chính -->
				<fieldset><legend>Dịch vụ chính</legend>
				<?php 
					$listData = CHtml::listData(DeliveryServicesModel::model()->published()->findAll(), 'id', 'name')
				?>
				<table>
					<tr>
					<td><?php echo $form->labelEx($model,'service'); ?></td>
					<td><input type="text" readonly="readonly" name="service_code" id="service_code" value="<?php if(isset($model->service) && $model->service>0) echo DeliveryServicesModel::model()->findByPk($model->service)->code;?>" style="width: 65px;margin-right: 5px;" />
					<?php echo $form->dropDownList($model, 'service', $listData, array('onChange'=>'getCodeservice(this.value)', 'prompt'=>'--None--')); ?></td>
					</tr>
					<tr>
					<td><?php echo $form->labelEx($model,'content'); ?></td>
					<td><?php echo $form->textArea($model, 'content'); ?></td>
					</tr>
					<tr>
					<?php $listData = CHtml::listData(PaymentModel::model()->published()->findAll(), 'id', 'name');?>
					<td><?php echo $form->labelEx($model,'payment'); ?></td>
					<td><?php echo $form->dropDownList($model, 'payment', $listData, array('prompt'=>'--None--')); ?></td>
					</tr>
					<tr>
					<td><?php echo $form->labelEx($model,'weight'); ?></td>
					<td><?php echo $form->textField($model, 'weight'); ?></td>
					</tr>
				</table>
				</div><!-- row -->
				</fieldset>
				
			</td>
			<td valign="top">
				<fieldset><legend>Trường hợp không gửi được</legend>
				<table class="lradio">
					<tr>
					<td colspan="3"><?php 
					//CHtml::radioButtonList($name, $select, $data);
					$data = array(
							1=>'<span style="font-size: 11px">Chuyển hoàn</span>',
							2=>'<span style="font-size: 11px">Chuyển tiếp</span>',
							3=>'<span style="font-size: 11px">Hủy</span>',
					);
					echo $form->radioButtonList($model, 'if_not_send', $data, array('separator'=>'&nbsp;')); ?></td>
					</tr>
				</table>
				</div><!-- row -->
				</fieldset>
				
				<!--  Thông tin người nhận -->
				<fieldset><legend>Thông tin người nhận</legend>
				<table>
					<tr>
						<td><?php echo $form->labelEx($model,'receive_address'); ?></td>
						<td><?php echo $form->textArea($model, 'receive_address', array('maxlength' => 255,)); ?></td>
					</tr>
					<tr>
						<td><?php echo $form->labelEx($model,'receiver_phone'); ?></td>
						<td><?php echo $form->textField($model, 'receiver_phone', array('maxlength' => 100,)); ?></td>
					</tr>
					<tr>
						<td><?php echo $form->labelEx($model,'office'); ?></td>
						<td><?php 
						$listData = CHtml::listData(OfficeModel::model()->published()->findAll(), 'id', 'name');
						echo $form->dropDownList($model, 'office', $listData, array('prompt'=>'--None--')); ?>
						</td>
					</tr>
				</table>
				</div><!-- row -->
				</fieldset>
				
			</td>
		</tr>
	</table>
	<fieldset><legend>Thông tin cước</legend>
	<table>
		<tr>
		<td>
			<?php echo $form->labelEx($model,'charge_pri'); ?>
			<?php echo $form->textField($model, 'charge_pri', array('maxlength' => 100, 'style'=>'width: 100px;')); ?>
		</td>
		<td>
			<?php echo $form->labelEx($model,'charge_more'); ?>
			<?php echo $form->textField($model, 'charge_more', array('maxlength' => 100, 'style'=>'width: 100px;')); ?>
		</td>
		<td>
			<?php echo $form->labelEx($model,'vat'); ?>
			<?php echo $form->textField($model, 'vat', array('maxlength' => 100, 'style'=>'width: 100px;')); ?>
		</td>
		<td>
			<?php echo $form->labelEx($model,'total'); ?>
			<?php echo $form->textField($model, 'total', array('maxlength' => 100, 'style'=>'width: 100px;')); ?>
		</td>
		</tr>
	</table>
	</fieldset>
	<table>
		<tr>
		<td align="right"><?php echo GxHtml::submitButton(Yii::t('DeliveryModule.main', 'Save'), array('class'=>'btn btn-success'));?>
		<?php echo GxHtml::button(Yii::t('DeliveryModule.main', 'Close'), array('class'=>'btn btn-primary', 'onclick'=>"window.location.href='".Yii::app()->createUrl('/delivery/deliveryOrderTicket/admin')."'"));?></td>
		</tr>
	</table>
<?php
$this->endWidget();
?>
</div><!-- form -->
<script>
	$(function(){
			$("#DeliveryOrderTicketModel_start_datetime").datepicker({
					'dateFormat':'yy-mm-dd'
				});
		})
function getCodeservice(id)
	{
		$.ajax({
				url:'<?php echo Yii::app()->createUrl('/delivery/deliveryServices/getCode');?>',
				data: {id:id},
				success: function(data){
					$("#service_code").attr("value",data);
					}
			})
	}
</script>